<template>
  <el-dialog title="角色" :visible="showDislog" append-to-body @close="hClose">
    <el-checkbox-group v-model="checkId">
      <el-checkbox v-for="item in checkList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
      <el-row>
        <el-button @click="hOk">确认</el-button>
        <el-button>取消</el-button>
      </el-row>
    </el-checkbox-group>
  </el-dialog>
</template>

<script>
import { getRoleEnabled } from '@/api/role'
import { getEmployeeDetail, assignRole } from '@/api/employee'
export default {
  props: {
    showDislog: {
      type: Boolean,
      required: true
    },
    cId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      checkList: [],
      checkId: []
    }
  },
  created() {
    this.lodaRole()
  },
  methods: {
    async hOk() {
      await assignRole({ id: this.cId, roleIds: this.checkId })
      this.$message.success('分配成功')
      this.hClose()
    },
    async getRoleBy() {
      const res = await getEmployeeDetail(this.cId)

      this.checkId = res.data.roleIds
    },
    async lodaRole() {
      const res = await getRoleEnabled()

      this.checkList = res.data
    },
    hClose() {
      this.$emit('update:showDislog', false)
    }
  }
}
</script>

<style>

</style>
